package com.ziyueyuwen.xiniao.controller.manage;

import com.suyeer.basic.util.HttpResUtil;
import com.ziyueyuwen.xiniao.base.BaseUtil;
import com.ziyueyuwen.xiniao.base.HttpResContent;
import com.ziyueyuwen.xiniao.bean.homework.ZySubjectDO;
import com.ziyueyuwen.xiniao.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author jun 2018/12/20.
 */
@Controller
@RequestMapping("/manage/subject")
public class ManageSubjectController {
    @Autowired
    private SubjectService subjectService;

    @Autowired
    private SubjectQuestionService subjectQuestionService;

    @Autowired
    private HomeworkRecordService homeworkRecordService;

    @Autowired
    private WxMessageService wxMessageService;

    @Autowired
    private UserService userService;

    /**
     * 获取所有套题名称, 用于绑定课程数据
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     */
    @RequestMapping(value = "/list_all_subject.do", method = RequestMethod.POST)
    public void listAllSubject(HttpServletRequest request, HttpServletResponse response) {
        HttpResContent<List<ZySubjectDO>> hrc = new HttpResContent<>(request, response);
        hrc.setFuncDes("获取所有套题名称");
        try {
            List<ZySubjectDO> retList = subjectService.listAll();
            BaseUtil.saveSuccessMsgAndData(hrc, retList);
        } catch (Exception e) {
            BaseUtil.saveErrorMsgAndData(hrc, e);
        } finally {
            HttpResUtil.writeResult(hrc, true);
        }
    }

}
